#include "FMDBParameter.h"
#include "DBTOOLS.h"

//note:here VarValueArray is a void* array, this is usful when caller want to run a series of DML statement
// for example if caller want to update or insert a set of record, the SQL statement could be the same except binding variable.
// use parameter array, we can get best performace for batch update,insert,etc
FMDBParameter::FMDBParameter( char *VarName, int *VarValueArray )
{
	m_pIndicator=NULL;
	Set(VarName,VarValueArray);

}

FMDBParameter::FMDBParameter( char *VarName,char *VarValueArray )
{
	m_pIndicator=NULL;
	Set(VarName,VarValueArray);

}

FMDBParameter::FMDBParameter( char *VarName,long *VarValueArray )
{
	m_pIndicator=NULL;
	Set(VarName,VarValueArray);

}

FMDBParameter::FMDBParameter( char *VarName,double *VarValueArray )
{
	m_pIndicator=NULL;
	Set(VarName,VarValueArray);
}

FMDBParameter::FMDBParameter( void )
{
	m_pIndicator=NULL;

}


FMDBParameter::~FMDBParameter(void)
{
}

void FMDBParameter::Set( char *VarName,double *VarValueArray )
{
	m_pstrVarName=NULL;
	DBTOOLS::CopyPropertyValue(&m_pstrVarName,VarName);
	m_VarValue=VarValueArray;

	m_VarDataType=SQLT_BDOUBLE;
}

void FMDBParameter::Set( char *VarName,char *VarValueArray )
{
	m_pstrVarName=NULL;
	DBTOOLS::CopyPropertyValue(&m_pstrVarName,VarName);
	m_VarValue=VarValueArray;

	m_VarDataType=SQLT_STR;
}

void FMDBParameter::Set( char *VarName,long *VarValueArray )
{
	m_pstrVarName=NULL;
	DBTOOLS::CopyPropertyValue(&m_pstrVarName,VarName);
	m_VarValue=VarValueArray;

	m_VarDataType=SQLT_INT;
}

void FMDBParameter::Set( char *VarName,int *VarValueArray )
{
	m_pstrVarName=NULL;
	DBTOOLS::CopyPropertyValue(&m_pstrVarName,VarName);
	m_VarValue=VarValueArray;

	m_VarDataType=SQLT_INT;
}


void FMDBParameters::AddParam( FMDBParameter *Param )
{
	//only check the para name should not be NULL
	if (Param)
	{
		if(Param->GetVarName())
		{
			m_vParam.push_back(Param);
		}
	}
}

void FMDBParameters::AddOCIIOVParam( FMDBIOVParameter *Param )
{
	//only check the para name should not be NULL
	if (Param)
	{		
		m_vIOVParam.push_back(Param);		
	}
}

void FMDBParameters::AddCursorParam( FMDBCursorParameter *Param )
{
	//only check the para name should not be NULL
	if (Param)
	{		
		m_vCursorParam.push_back(Param);		
	}
}

FMDBIOVParameter::FMDBIOVParameter( char *VarName,OCIIOV *VarValueArray,ub4 ArraySize,ub2 VarOraDataType )
{
	m_pstrVarName=NULL;
	DBTOOLS::CopyPropertyValue(&m_pstrVarName,VarName);
	m_VarValue=VarValueArray;
	m_ValueArraySize=ArraySize;
	m_VarDataType=VarOraDataType;
	//note:here I do not keep varValue,so the caller must keep the value available till finish the executing.
}

FMDBCursorParameter::FMDBCursorParameter( char *VarName,OCIStmt *VarValue,FMDBRecordSet *Rs )
{
	m_pstrVarName=NULL;
	DBTOOLS::CopyPropertyValue(&m_pstrVarName,VarName);
	m_VarValue=VarValue;
	m_pRs=Rs;
}

FMDBCursorParameter::~FMDBCursorParameter( void )
{

}


FMDBParameters::~FMDBParameters(void)
{

}